/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.client  
 */
package com.apache.client;

import java.util.Map;

import com.apache.api.vo.ResultEntity;
import com.apache.client.protocol.HttpProtocolService;
import com.apache.client.protocol.HttpsProtocolService;
import com.apache.client.protocol.SocketProtocolService;
import com.apache.uct.common.ToolsUtil;

/**
 * description:  用户中心客户端协议调用工具
 * @author dwusoftwu 创建时间：2015-3-31  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class UctProtoclClient {

	private static UctProtoclClient instance;
	private HttpProtocolService httpService;
	private HttpsProtocolService httpsService;
	private SocketProtocolService socketService;

	private UctProtoclClient() {
		httpService = new HttpProtocolService("/uct/service/doService.action", "uct_server");
		httpsService = new HttpsProtocolService("/uct/service/doService.action", "uct_server");
		socketService = new SocketProtocolService();
	}

	public static UctProtoclClient getInstance() {
		if (null == instance) {
			instance = new UctProtoclClient();
		}
		return instance;
	}

	public ResultEntity doService(String beanId, String methodKey, Map<String, Object> params) {
		String protocolType = ToolsUtil.getInstance().getClientValueByKey("protocol_type");
		if (ToolsUtil.isNull(protocolType)) {
			protocolType = "socket";
		}
		if ("socket".equals(protocolType)) {
			return socketService.doService(beanId, methodKey, params);
		} else if ("http".equals(protocolType)) {
			return httpService.doService(beanId, methodKey, params);
		} else {
			return httpsService.doService(beanId, methodKey, params);
		}
	}
}
